import { message } from 'antd';
import {
  getDetailData,
  getproselectedList,
  getSendDetailData,
  signPro,
  getProDetail,
  getFeedback,
  getFeedbacks,
} from '@/services/salarymanagens';

export default {
  state: {
    formFieldsValue: {},
    expandForm: false,
    activeKey: '1',
    proInsuranceList: [],
    detailList: {},
    probRecord: [],
  },
  effects: {
    // 工资查看 - 获取详情
    *getDetailMessage({ payload }, { call, put }) {
      const response = yield call(getDetailData, payload);
      yield put({
        type: 'getDetail',
        payload: {
          data: {},
        },
      });
      if (response.success) {
        yield put({
          type: 'getDetail',
          payload: {
            data: response.data,
          },
        });
      } else {
        message.warning(`${response.message || '服务端错误！'}`);
      }
    },

    // 工资发放 - 获取详情
    *getSendDetailMessage({ payload }, { call, put }) {
      const response = yield call(getSendDetailData, payload);
      if (response.success) {
        yield put({
          type: 'getDetail',
          payload: {
            data: response.data,
          },
        });
      } else {
        message.warning(`${response.message || '服务端错误！'}`);
      }
    },

    // 标记问题人员
    *tabProb({ payload, callback }, { call }) {
      const response = yield call(signPro, payload);
      if (callback) {
        callback(response);
      }
    },

    // 问题人员反馈
    *proFeedBack({ payload, callback }, { call }) {
      const response = yield call(getFeedback, payload);
      if (response.success) {
        if (callback) {
          callback(response);
        }
      }
    },

    // 问题人员反馈并取消标记
    *cancelProbFlag({ payload, callback }, { call }) {
      const response = yield call(getFeedbacks, payload);
      callback(response);
    },

    // 问题人员详情
    *feactProDetail({ payload }, { call, put }) {
      const response = yield call(getProDetail, payload);
      if (response.success) {
        yield put({
          type: 'getProDetail',
          payload: response.data,
        });
      }
    },

    // 获取问题对象的险种
    *selectedRowsList({ payload }, { call, put }) {
      const payloads = {
        recvAddTaskIds: payload,
      };
      const response = yield call(getproselectedList, payloads);
      if (response.success) {
        yield put({
          type: 'getProInsuranceList',
          payload: response,
        });
      } else {
        message.warning(response.message || '查询失败！');
      }
    },
  },

  reducers: {
    // 设置查询时保存的值
    getDetail(state, { payload }) {
      return {
        ...state,
        detailList: payload.data,
      };
    },

    // 标记问题人员的问题对象列表
    getProInsuranceList(state, { payload }) {
      return {
        ...state,
        proInsuranceList: payload.data,
      };
    },

    monUpdate(state) {
      return {
        ...state,
        detailList: {},
      };
    },

    // 问题人员详情
    getProDetail(state, { payload }) {
      return {
        ...state,
        proBaseList: payload,
        probRecord: payload.probRecord,
      };
    },
  },
};
